package com.sn.pw.page;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.util.Date;

/**
 * @author Mr.Zhu
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class PageReq implements Serializable {
    @ApiModelProperty(value = "起始页")
    private int page = 1;
    @ApiModelProperty(value = "每页展示数据")
    private int row = 10;
    @ApiModelProperty(value = "排序字段")
    private String orderField;
    @ApiModelProperty(value = "排序方式 asc  desc")
    private String order = "desc";
    @ApiModelProperty(value = "基础搜索条件")
    private String searchCondition;
    @ApiModelProperty(value = "开始日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "Asia/Shanghai")
    private Date startDate;
    @ApiModelProperty(value = "结束日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "Asia/Shanghai")
    private Date endDate;

    public void setEndDate(Date endDate) {
        if (ObjectUtil.isNotEmpty(endDate)) {
            endDate = DateUtil.offsetDay(endDate, 1);
        }
        this.endDate = endDate;
    }
}
